home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / zeke / gui.h < prev   
C/C++ Source or Header  |  1995-02-13  |  11KB  |  292 lines

  1. gui.h
  2.  
  3. #ifndef _GUI_
  4. #define _GUI_
  5.  
  6. #include <stdarg.h>
  7.  
  8. // platform specific includes and defines
  9.  
  10. #ifdef WIN_NT
  11.     #include <windows.h>
  12.  
  13.     typedef HWND NativeWindow;
  14.     typedef HDC  GraphicsHandle;
  15.     #define EXP1
  16.     #define EXP2 __declspec(dllexport)
  17.     #define NATIVE_PART_OF_GUI_APPLICATION HINSTANCE hInstance
  18.     #define NATIVE_PART_OF_GUI_WINDOW
  19.     #define NATIVE_FRIEND_OF_GUI_WINDOW    friend LRESULT CALLBACK \
  20.             GuiWindowProc(HWND hWnd, UINT message, \
  21.                           WPARAM uParam, LPARAM lParam)
  22.     #define main  ApplicationMain
  23. #endif
  24.  
  25. #ifdef OS2
  26.     #define INCL_WIN
  27.     #define INCL_GPI
  28.     #include <os2.h>
  29.  
  30.     typedef HWND   NativeWindow;
  31.     typedef HPS    GraphicsHandle;
  32.     #define EXP1   _export
  33.     #define EXP2
  34.     #define NATIVE_PART_OF_GUI_APPLICATION HAB Hab; \
  35.                                            HMQ Hmq
  36.     #define NATIVE_PART_OF_GUI_WINDOW      NativeWindow frame
  37.     #define NATIVE_FRIEND_OF_GUI_WINDOW    friend MRESULT \
  38.             EXPENTRY GuiWindowProc(HWND hwnd, USHORT msg, \
  39.                                    MPARAM mp1, MPARAM mp2)
  40. #endif
  41.  
  42. #ifdef X_WINDOWS
  43.     #include <X11/Intrinsic.h>
  44.  
  45.     typedef Widget NativeWindow;
  46.     typedef GC     GraphicsHandle;
  47.     #define EXP1
  48.     #define EXP2
  49.     #define NATIVE_PART_OF_GUI_APPLICATION int dontQuit
  50.     #define NATIVE_PART_OF_GUI_WINDOW      NativeWindow frame; \
  51.                                            char         szGeometry[100]
  52.     #define NATIVE_FRIEND_OF_GUI_WINDOW    \
  53.                   friend void ExposeCallback(Widget w,
  54.                                              XtPointer client_data, \
  55.                                              XtPointer call_data); \
  56.                   friend void ResizeCallback(Widget w,
  57.                                              XtPointer client_data, \
  58.                                              XtPointer call_data)
  59. #endif
  60.  
  61. // coordinate system definition
  62.  
  63. #define MAX_X              10000
  64. #define MAX_Y              10000
  65.  
  66. #define MAX_WINDOW         100 // max. windows in an application
  67. #define MAX_CHILDREN       100 // max. children of a window
  68.  
  69. // VGA colors
  70.  
  71. #define COLOR_WHITE        0
  72. #define COLOR_BLACK        1
  73. #define COLOR_BLUE         2
  74. #define COLOR_RED          3
  75. #define COLOR_PINK         4
  76. #define COLOR_GREEN        5
  77. #define COLOR_CYAN         6
  78. #define COLOR_YELLOW       7
  79. #define COLOR_NEUTRAL      8
  80. #define COLOR_DARKGRAY     9
  81. #define COLOR_DARKBLUE     10
  82. #define COLOR_DARKRED      11
  83. #define COLOR_DARKPINK     12
  84. #define COLOR_DARKGREEN    13
  85. #define COLOR_DARKCYAN     14
  86. #define COLOR_BROWN        15
  87.  
  88. // object types returned by GetType()
  89.  
  90. #define TYPE_LINE          1
  91. #define TYPE_ELLIPSE       2
  92. #define TYPE_TEXT          3
  93. #define TYPE_BUTTON        4
  94. #define TYPE_ENTRY         5
  95. #define TYPE_WINDOW        6
  96.  
  97. // the only global function: logs into a file
  98. EXP2 void EXP1 Log(char* fmt, ...);
  99.  
  100. // forward declaration of classes GUI_WINDOW and GUI_OBJECT
  101. class GUI_WINDOW;
  102. class GUI_OBJECT;
  103.  
  104. typedef struct _GUI_WINDOW_ELEM { // typedef for linked list of windows
  105.    GUI_WINDOW*              pWindow;
  106.    struct _GUI_WINDOW_ELEM* pNext;
  107. } GUI_WINDOW_ELEM;
  108.  
  109. class EXP1 GUI_APPLICATION {
  110.     private:
  111.        NATIVE_PART_OF_GUI_APPLICATION;
  112.  
  113.        GUI_WINDOW_ELEM WindowElemList[MAX_WINDOW], *pUsed, *pFree;
  114.        int             AddWindow(GUI_WINDOW *pWindow);
  115.        int             DelWindow(GUI_WINDOW *pWindow);
  116.     public:
  117.        EXP2 GUI_APPLICATION(int* pArgc, char** argv, char* logFile);
  118.        EXP2 virtual     ~GUI_APPLICATION(void);
  119.        EXP2 void        MainLoop(void);
  120.        EXP2 void        Terminate(void);
  121.        EXP2 GUI_WINDOW* FindWindow(NativeWindow window);
  122.        EXP2 GUI_OBJECT* FindChild(NativeWindow window);
  123.  
  124.     friend class GUI_WINDOW;
  125. };
  126.  
  127. class EXP1 CALLABLE_OBJECT {
  128.     public:
  129.        EXP2 virtual int Activate(void) { return(1); }
  130.        EXP2 virtual int LeftClick(void) { return(1); }
  131.        EXP2 virtual int RightClick(void) { return(1); }
  132.        EXP2 virtual int LeftDoubleClick(void) { return(1); }
  133.        EXP2 virtual int RightDoubleClick(void) { return(1); }
  134. };
  135.  
  136. class EXP1 GUI_OBJECT: public CALLABLE_OBJECT { // abstract class
  137.     protected:
  138.         GUI_WINDOW* pParent;
  139.         int         id, x, y, width, height;
  140.     public:
  141.         EXP2 GUI_OBJECT(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  142.                    int width=MAX_X, int height=MAX_Y);
  143.         EXP2 virtual              ~GUI_OBJECT(void);
  144.         EXP2 virtual int          GetType(void)=0;
  145.         EXP2 virtual void         Paint(GraphicsHandle gh) { }
  146.         EXP2 virtual NativeWindow GetNativeWindow(void) { return(0); }
  147.         EXP2 GUI_WINDOW*          GetParent(void) { return(pParent); }
  148.         EXP2 int                  GetId(void) { return(id); }
  149.         EXP2 int                  GetX(void) { return(x); }
  150.         EXP2 int                  GetY(void) { return(y); }
  151.         EXP2 int                  GetWidth(void) { return(width); }
  152.         EXP2 int                  GetHeight(void) { return(height); }
  153. };
  154.  
  155. class EXP1 GUI_GRAPHICS_OBJECT: public GUI_OBJECT { // abstract class
  156.     protected:
  157.         int color, lineWidth;
  158.     public:
  159.         EXP2 GUI_GRAPHICS_OBJECT(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  160.                             int width=MAX_X, int height=MAX_Y,
  161.                             int color=COLOR_BLACK, int lineWidth=1);
  162.         EXP2 virtual ~GUI_GRAPHICS_OBJECT(void);
  163. };
  164.  
  165. class EXP1 GUI_LINE: public GUI_GRAPHICS_OBJECT {
  166.     public:
  167.         EXP2 GUI_LINE(GUI_WINDOW* pParent, int id, int x1=0, int y1=0,
  168.                  int x2=MAX_X, int y2=MAX_Y,
  169.                  int color=COLOR_BLACK, int lineWidth=1);
  170.         EXP2 virtual      ~GUI_LINE(void);
  171.         EXP2 virtual int  GetType(void) { return(TYPE_LINE); }
  172.         EXP2 virtual void Paint(GraphicsHandle gh);
  173. };
  174.  
  175. // fill types
  176.  
  177. #define FILL_OUTER         0  // draw just the otline
  178. #define FILL_SOLID         1  // draw and fill the shape
  179.  
  180. class EXP1 GUI_ELLIPSE: public GUI_GRAPHICS_OBJECT { // abstract class
  181.     protected:
  182.         int fillType;
  183.     public:
  184.         EXP2 GUI_ELLIPSE(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  185.                  int width=MAX_X/2, int height=MAX_Y/2,
  186.                  int color=COLOR_BLACK, int fillType=FILL_OUTER,
  187.                  int lineWidth=1);
  188.         EXP2 virtual      ~GUI_ELLIPSE(void);
  189.         EXP2 virtual int  GetType(void) { return(TYPE_ELLIPSE); }
  190.         EXP2 virtual void Paint(GraphicsHandle gh);
  191. };
  192.  
  193. class EXP1 GUI_WINDOW_OBJECT: public GUI_OBJECT { // abstract class
  194.     protected:
  195.         NativeWindow window;
  196.     public:
  197.         EXP2 GUI_WINDOW_OBJECT(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  198.                           int width=MAX_X, int height=MAX_Y);
  199.         EXP2 virtual      ~GUI_WINDOW_OBJECT(void);
  200.         EXP2 NativeWindow GetNativeWindow(void) { return(window); }
  201.         EXP2 virtual void GetRealCoordinates(int *pRx, int *pRy,
  202.                                         int *pRw, int *pRh);
  203.         EXP2 virtual int  GetText(char *buffer, int bufferLength);
  204.         EXP2 virtual int  SetText(char *text="");
  205. };
  206.  
  207. class EXP1 GUI_TEXT: public GUI_WINDOW_OBJECT {
  208.     public:
  209.         EXP2 GUI_TEXT(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  210.                  int width=MAX_X, int height=0,
  211.                  char *text="");
  212.         EXP2 virtual int  GetType(void) { return(TYPE_TEXT); }
  213. };
  214.  
  215. class EXP1 GUI_BUTTON: public GUI_WINDOW_OBJECT {
  216.     public:
  217.         EXP2 GUI_BUTTON(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  218.                    int width=MAX_X, int height=0,
  219.                    char* text="");
  220.         EXP2 virtual int  GetType(void) { return(TYPE_BUTTON); }
  221. };
  222.  
  223. class EXP1 GUI_ENTRY: public GUI_WINDOW_OBJECT {
  224.     protected:
  225.         int length;
  226.     public:
  227.         EXP2 GUI_ENTRY(GUI_WINDOW* pParent, int id, int x=0, int y=0,
  228.                    int width=MAX_X, int height=0,
  229.                    char* text="", int maxTextLength=10);
  230.         EXP2